<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
<title>设置项目文档的内容复用</title>
</head>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="${_resources}bootstrap/bootstrap-table.min.css" />
<script type="text/javascript" src="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.js"></script>
<link rel="stylesheet" href="${_resources}jquery-ui/jquery-ui-1.10.4.custom.min.css" />
<script type="text/javascript">
var contentReuseList;
var projectId = "${projectId}";
var contentCopyTemplateId= "${contentCopyTemplateId}";
var ids = "${ids}";
$(function (){	
	contentReuseList = $("#contentReuseList").bootstrapTable({
		url : '${_baseUrl}/kmDemandTraceController/getContentReuseList?projectId='+projectId+"&rand="+Math.random(),
		pagination: true,
		pageList: [5, 10, 20, 50],
  		queryParams: queryParams,
        columns: [{
            title: '序号',
            width: 45,
            formatter: function(value, row, index){
            	return index+1;
            }
        }, {
            field: 'id',
            title: 'id',
            visible:false,
            width: 5
        },{
            field: 'reuseDocumentName',
            title: '引用文档',
            width: 150,
            formatter: function(value, row, index){
            	return "<a onclick=\"updateReuseDocument('"+row.id+"');\">"+value+"</a>";
            }
        },{
            field: 'reuseSectionName',
            title: '引用文档章节',
            width: 90,
        },{
            field: 'applyDocumentName',
            title: '适用文档',
            width: 150,
            formatter: function(value, row, index){
            	return "<a onclick=\"updateApplyDocument('"+row.id+"');\">"+value+"</a>";
            }
        },{
            field: 'applySectionName',
            title: '适用文档章节',
            width: 90,
            formatter: function(value, row, index){
            	if(row.applySectionName!=null){
            		var applySectionName=row.applySectionName.substring(1);
                	return applySectionName;
            	}
            	return applySectionName;
            }
        },{
	            title: '操作',
	            width: 65,
	            formatter: function(value, row, index){
	            	return "<a onclick=\"deleteContentReuse('"+row.id+"');\">删除</a>";
	            }
        }]
    });

	/*选择引用文档内容和适用文档章节"*/
	$("#documentReference").click(function (){
		window.location.href = "${_baseUrl}/kmDemandTraceController/showDocumentReference?contentCopyTemplateId="+contentCopyTemplateId+"&projectId="+projectId+"&ids="+ids+"&rand="+Math.random();
		
	});
	
	function queryParams(params){
		return {
		    pageSize: params.limit,
		    pageNo: params.pn,
		    sort : params.sort,
		    order : params.order,
		    projectName:$("#projectName").val()
	   }
	}
});
function deleteContentReuse(id){
	
	  $.ajax({
			url:'${_baseUrl}/kmDemandTraceController/deleteContentReuse', 
			data:{"id":id},
			type:'post', //数据发送方式 
			dataType:'json', //接受数据格式 
			async: false,
			success: function(json){
				layer.msg(json.message);
				refreshTable();	
				
        },
			error:function(){
				layer.msg(json.message);
			}
		});  
}
function updateReuseDocument(id){
	var s= testApplyDocumentIssue(id);
	if("3"==s){
		layer.msg("适用文档已发布，不能修改引用文档章节");//[#3353] 提示语规范，内容复用，适用文档已发布时，提示语修改
		return false;
	}
	/*  $("#popIframe").empty();
	$("#popDiv").dialog({
		title:'修改引用文档章节',
		autoOpen: true,
		modal: true,	
		height: 600,
		width: 600,
	});
	$("#popIframe").attr("width","100%");
	$("#popIframe").attr("height","95%");
	$("#popIframe").attr("src","${_baseUrl}/demand/updateReuseDocument?id="+id);  */
	layerIndex =layer.open({
		  type: 2, 
		  title:'修改引用文档章节',
		  area: ['600px', '400px'],
		  fixed: false, //不固定
		  maxmin: true,
		  content: "${_baseUrl}/kmDemandTraceController/updateReuseDocument?id="+id+"&rand="+Math.random()
		});
}
function updateApplyDocument(id){
	var s= testApplyDocumentIssue(id);
	if("3"==s){
		layer.msg("适用文档已发布，不能修改适用文档章节");//[#3353] 提示语规范，内容复用，适用文档已发布时，提示语修改
		return false;
	}
	/* $("#popIframe").empty();
		 $("#popDiv").dialog({
			title:'修改适用文档章节',
			autoOpen: true,
			modal: true,	
			height: 600,  
			width: 600,
		});
		$("#popIframe").attr("width","100%");
		$("#popIframe").attr("height","95%");
		$("#popIframe").attr("src","${_baseUrl}/demand/updateApplyDocument?id="+id);  */
		layerIndex =layer.open({
			  type: 2, 
			  title:'修改适用文档章节',
			  area: ['600px', '400px'],
			  fixed: false, //不固定
			  maxmin: true,
			  content: "${_baseUrl}/kmDemandTraceController/updateApplyDocument?id="+id+"&rand="+Math.random()
			});
}
function closewin(){
	//$("#popDiv").dialog("close");
	layer.closeAll();
}

function refreshTable(){
	contentReuseList.bootstrapTable('refresh');
}
function testApplyDocumentIssue(id){
	 var status=0;
	 $.ajax({
			url:'${_baseUrl}/kmDemandTraceController/testApplyDocumentIssue', 
			data:{"id":id},
			type:'post', //数据发送方式 
			dataType:'json', //接受数据格式 
			async: false,
			success: function(json){
			status=json.message;
				
     },
			error:function(){
				layer.msg(json.message);
			}
		});  
	 return status;
};
$(function(){
	$("#popDiv").on( "dialogclose", function( event, ui ) {
		contentReuseList.bootstrapTable('refresh');
	} );
});
</script>
<style type="text/css">
.fixed-table-container{border:0px}
table{border:1px solid #ddd;margin-top: 7px!important;}
.fixed-table-header{height:0px}
.func_bar{margin: 15px auto 0px;}
</style>
<body>
<div class="submenu">
    <div class="func_bar">
        <div class="btn_container">
            <a class="blue_btn" id="documentReference" href="javascript:;">添加</a>
        </div>
    </div>
    <div style="overflow: auto; width:98%;margin: auto;">
    	<table id="contentReuseList" class="table table-bordered table_inline"></table>
	</div>
</div>
   <!--  <div  class="wdang_c mt20" >
         	<div class="wdang_dy" style="position:relative;" >
         		<div class="fl wdang_dy_l" >
	                 <dl >
	                    <dd style="position:absolute; right:0;"><input id="documentReference" value="新增" type="button" class="dyi_btna dyi_btnabox dyi_btna1"></dd>
	                </dl>
		        </div>
            <div class="clear"></div>
          	</div>
          	<div class="wdang_s" >
             	 <table id="contentReuseList" style="overflow:hidden;" class="tab-w-01 tab-w-auto" width="100%" border="0" cellspacing="0" cellpadding="0">
        			</table>     	
         	</div>      	
	</div> 
	<div id="popDiv" style="display: none; overflow:hidden;">
	<iframe id="popIframe" border="0" frameborder="0"></iframe>
</div>  -->   	
</body>
</html>